from lbuffermod import lbuffer 

# this needs a keyed nclude list
# heirarchy - divsforms_tagscsclass
#                 | divsforms declares all the varnames which wsgi/json can own on a page
#                 | any given element refers to the very-top
#                 |
#                 | wsgi installs ajax - ajax reports browser stats
#                 | wsgi reads ajax and makes determinations about templating page elements
#                 |     |
#                 |     wsgi checks its plugins for form_data and content_data reserves div: fdiv, div: ddiv names  
#                 |     wsgi makes determinations about width and height, builds dom, installs
#                 |
#                 |
#                 |
#
##
# Start this by implementing a refresh call to werkzeug, and a file save form. gut your raw code into the class.
##
#
class flatout(object):
    def __init__(self,cssbufs,jsbufs,htmlbufs):
        arb = "hello world"
        self.cssbufs = cssbufs
        self.jsbufs = jsbufs
        self.htmlbufs = htmlbufs       
    def cssheadout(self):
        self.lcssheadout = '<head><style>'
        for x in self.cssbufs:
            self.lcssheadout += lbuffer(x).flatbuffer
        self.lcssheadout += '</style>'
        return self.lcssheadout
    def jsheadout(self):
        self.ljsheadout = '<script>'
        for x in self.jsbufs:
            self.ljsheadout += lbuffer(x).flatbuffer
        self.ljsheadout += '</script></head>'
        return self.ljsheadout
    def bodyout(self):
        self.lhtmlout = ''
        for x in self.htmlbufs:
            self.lhtmlout += lbuffer(x).flatbuffer
        self.lhtmlout += '</html>'
        return self.lhtmlout
    def lout(self):
        self.cflatout = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>'
        self.cflatout += self.cssheadout()
        self.cflatout += self.jsheadout()
        self.cflatout += self.bodyout()
        return self.cflatout

##
# 
#cssbufs = ['css/bf.css','css/images.css']
#jsbufs = ['js/gf.js']
#thing = flatout(cssbufs,jsbufs,htmlbufs)
#thing.lout
#csstempbufs,jstempbufs,htmltempbufs = ['js/2ZeroClipboard_nb_user_template.js'],['css/bf_user_template.css'],['zcb_user_template.html']
#kellist = [ ["fe_text_","arb_1"], ["for_fun","hello world"],["fe_text_id","arb_1"] ]
#thing = flatout(csstempbufs,jstempbufs,htmltempbufs)
#template = Template(thing.bodyout())
#template.render(fe_text_=kellist[0][0],fe_text_id=kellist[0][1])
## ^^^^
#   |
#   In case you forget- this is useful when taking prog_name and attacking it to prog_name_id. yes were stuck with fe_text_ but we can make more 
#   of them in a generator!
# like:
#  for x in range(5):
#      template.render(elem_int=str(x))
#

## 
#  open the txt file and get the number of copyables from it. call it elem_int
# the internal jscript needs to independantly render all the copyables, and the html file has to match it on the class names
# stubstitude 10 in elem_int until there is a text file parsed.

#
# css file has no elem_int- so according to this code, elem_int needs to be 1 and not 10 and these funcs should be called seperately
# 

from jinja2 import Template
from lbuffermod import lbuffer
class ohill(object):
    def __init__(self):
        self.cssout = ''
        self.jsout = ''
        self.bodyout = ''
        return
    def csstems(self,csstempbufs,lelem_int):
        for x in csstempbufs:
            self.cssout += lbuffer(x).flatbuffer
        csstemp = Template(self.cssout)
        csstempout = '<head><style>'
        for x in range(lelem_int):
            csstempout += csstemp.render(for_fun=str(x))
        csstempout += '</style>'
        return csstempout 
    def jstems(self,jstempbufs,lelem_int):
        for x in jstempbufs:
            self.jsout += lbuffer(x).flatbuffer        
        jstempout = '<script>'
        jstempout += lbuffer('js/ZeroClipboard.js').flatbuffer
        jstempout += lbuffer('js/2ZeroClipboard_init_user_template.js').flatbuffer
        jstemp = Template(self.jsout)
        for x in range(lelem_int):
            jstempout += jstemp.render(elem_int=str(x))
        jstempout += lbuffer('js/2ZeroClipboard_close_user_template.js').flatbuffer
        jstempout += '</script></head>'
        return jstempout
    def bodytems(self,htmltempbufs,lelem_int,lelem_bufs):
        for x in htmltempbufs:
            self.bodyout += lbuffer(x).flatbuffer
        bodytemp = Template(self.bodyout)
        bodytempout = lbuffer('2zcb_init_user_template.html').flatbuffer
        for x in range(lelem_int):
            #print x
            #print lelem_bufs[x]
            bodytempout += bodytemp.render(fe_text_=str(x),elem_int=str(x),instance_text=lelem_bufs[x])
        bodytempout += lbuffer('2zcb_close_user_template.html').flatbuffer
        return bodytempout



